//
// Created by ins on 2021/2/28.
//

#ifndef SERVICE_UTIL_H
#define SERVICE_UTIL_H
#include <iostream>
#include <string>
#include <json.h>

using namespace std;
class Util {
public:

    static string getTime(){

        time_t timeTemp = time(nullptr);
        timeTemp += 8*3600;
        char temp[50];
        struct tm * timeSet = gmtime(&timeTemp);
        strftime(temp,50, "%Y-%m-%d %H:%M:%S", timeSet);
        return temp;
    }

    static Json::Value init_root(string data){
        Json::Value root;
        Json::String  jsError;
        Json::CharReaderBuilder readerBuilder;
        std::unique_ptr<Json::CharReader>reader(readerBuilder.newCharReader());

        if(!reader->parse(data.c_str(), data.c_str()+data.length(), &root, &jsError)){
            cout << "invalid input" << endl;
        }
        return root;
    }
};


#endif //SERVICE_UTIL_H
